<template>
	<view class="choose-ticket">
		<view v-for="(item,index) in ticketList" :key="index" class="record-detail" @click="chooseTicket(item)">
			<view class="detail-top">
				<view class="mb-20 flex-center justify-space-between record-name">
					<view class="font-24 name">{{item.ticketName}}</view>
				</view>
				<view class="flex-center justify-start info-box">
					<view class="flex-center mr-30 icon-box">
						<image src="../../../static/images/blue_bg.png" class="bg1"></image>
						<image src="../../../static/images/record_bg.png" class="bg2"></image>
					</view>
					<view class="font-20 info">
						<view>票券号码：{{item.ticketNo}}</view>
						<view>手机号码：{{item.recevieUserPhone}}</view>
						<view class="d-flex align-center  mt-20" >
							<view class="d-flex align-center font-24 " style="color: #E68700; font-weight: bold;width: 200rpx;">已核销：<text>{{item.alreadyWriteOffNumber}}次</text></view>
							<view class="d-flex align-center font-24" style="color: #E68700; font-weight: bold;width: 200rpx;">剩余：<text>{{item.remainsWriteOffNumber == null ? '0' : item.remainsWriteOffNumber}}次</text></view>
						</view>
					</view>
					
				</view>
				<image v-if="ticketNo == item.ticketNo" src="../static/images/select.png" class="select-icon"></image>
			</view>
		</view>
		<view class="flex-center flex-column no-data" v-if="ticketList.length == 0">
			<image src="@/static/images/nodata.png" mode=""></image>
			<text>暂无数据</text>
		</view>
		<view class="zhanwei"></view>
		<view class="confirm">
			<view @click="confirm">确认选择</view>
		</view>
	</view>
</template>

<script>
	import { selectWriteOffList, writeOff } from '@/api/home.js'
	export default {
		data() {
			return {
				ticketList:[],
				radioCurrent: null,
				phoneNo: null,
				ticketNo: null
			}
		},
		onLoad(options) {
			this.getTicketList(options.phone)
		},
		methods: {
			getTicketList(phone) {
				selectWriteOffList({
					page: 1,
					size: 1000,
					phoneNo: phone
				}).then(res=>{
					this.ticketList = res.data.list
					
				})
				// this.ticketList = [{
				// 	ticketName: '电子票——叫啥叫啥',
				// 	ticketNo: '36546545dfd',
				// 	recevieUserPhone: '13512345678',
				// 	alreadyWriteOffNumber: 5,
				// 	remainsWriteOffNumber: 6
				// },{
				// 	ticketName: '电子票——叫啥ddf叫啥',
				// 	ticketNo: '36546545dfdddd',
				// 	recevieUserPhone: '13512345678',
				// 	alreadyWriteOffNumber: 5,
				// 	remainsWriteOffNumber: 6
				// }]
			},
			chooseTicket(item) {
				this.phoneNo = item.recevieUserPhone
				this.ticketNo = item.ticketNo
			},
			confirm () {
				if(this.phoneNo == null) {
					uni.showToast({
						title: '请选择需要核销的票券',
						duration: 2000,
						icon: "none"
					})
				} else {
					writeOff({
						no: this.ticketNo,
						phone: this.phoneNo
					}).then(res=>{
						const data = JSON.stringify(res.data)
						uni.navigateTo({
						  url: `../sale-success/sale-success?data=${data}&mark=2`,
						});
					}).catch(err => {
						uni.showToast({
							title: err.msg,
							duration: 2000,
							icon: "none"
						})
					})
				} 
			}
		}
	}
</script>
<style>
page{
	background:#eee;
	padding: 30rpx;
	box-sizing: border-box;
}
</style>

<style lang="scss" scoped>
.choose-ticket{
	.title{
		text-indent:2rem;
		font-size:28rpx;
		color:#999999;
		font-weight:400;
		line-height:100rpx;
	}
	.record-detail {
		background: #fff;
		padding: 20rpx 30rpx;
		margin: 16rpx auto;
		border-radius: 10rpx;
				
		.detail-top {
			position: relative;
			view {
				color: #000;
				font-weight: 400;
				line-height: 36rpx;
			}
				
			.record-name {
				font-weight: bold;
				color: #000;
				.name {
					font-weight: 400;
					color: #000;
					width: 394rpx;
					@include text-break;
					@include text-ellipsis-line;
				}
				
				.scenic {
					text-align: right;
					font-weight: 400;
					color: #000;
					width: 168rpx;
					@include text-break;
					@include text-ellipsis-line;
				}
			}
				
			.info-box {
				.icon-box {
					position: relative;
					width: 170rpx;
					height: 170rpx;
					.bg1 {
						position: absolute;
						width: 170rpx;
						height: 170rpx;
					}
				
					.bg2 {
						position: absolute;
						width: 42rpx;
						height: 46rpx;
					}
				}
				
			}
			.select-icon {
				width: 40rpx;
				height: 40rpx;
				position: absolute;
				right: 0rpx;
				top: 93rpx;
			}
		}
				
		.detail-bottom {
			margin-top: 30rpx;
				
			view {
				font-size: 24rpx;
				font-weight: 400;
				color: #262626;
				
				text {
					color: #262626;
				}
			}
		}
	}
	.no-data {
		width: 100%;
		height: 300rpx;
		
		image {
			width: 200rpx;
			height: 180rpx;
			margin-bottom: 10rpx;
		}
		text {
			color: #999;
		}
	}
	.zhanwei {
		height: calc(env(safe-area-inset-bottom) + 100rpx);
	}
	.confirm{
		width: 750rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		background: #fff;
		padding: 30rpx 0;

		view{
			width:50%;
			margin:0 auto;
			line-height:90rpx;
			background:#F4C233;
			text-align:center;
			border-radius: 45rpx;
			color:#000;
			font-size: 30rpx;
			font-weight:400;
		}
	}
}
</style>
